#ifndef DEV_H
#define DEV_H

#define     DEV_NAME_SIZE       32

enum{
    DEV_UNKNOWN = 0,
    DEV_TTY,
    DEV_DISK,
};

struct _dev_desc_t;
//dev_desc_t和device_t的区别,举例说明为:dev_desc_t相当于描述的是手机,device_t相当于描述的是苹果手机
//描述某一种类型的设备下的某个具体类型的设备
typedef struct _device_t
{
    struct _dev_desc_t* desc;

    int mode;   //模式(只读,可写等)
    int minor;  //次设备号

    void* data;
    int open_count;
}device_t;


//描述某一种类型的设备
typedef struct _dev_desc_t
{
    char name[DEV_NAME_SIZE];
    int major;  //设备类型(主设备号)
    
    //定义设备的函数指针
    int (*open)(device_t* dev); 
    int (*read)(device_t* dev,int addr,char* buf,int size);
    int (*write)(device_t* dev,int addr,char* buf,int size);
    int (*control)(device_t* dev,int cmd,int arg0,int arg1);
    void (*close)(device_t* dev);
}dev_desc_t;

int dev_open(int major,int minor,void* data);
int dev_read(int dev_id,int addr,char* buf,int size);
int dev_write(int dev_id,int addr,char* buf,int size);
int dev_control(int dev_id,int cmd,int arg0,int arg1);
void dev_close(int dev_id);


#endif